package com.sinopec.android;

import com.sinopec.android.constant.ConfigAttrs;
import com.sinopec.android.constant.Constants;
import com.sinopec.android.util.SharePreferencesUtil;
import com.sinopec.android.util.StringUtil;
import com.sinopec.android.util.ToastUtil;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

/**
 * 设置ip
 * @author Administrator
 *
 */
public class SetIpActivity extends BaseActivity {
	private Button save_ip_btn;
	private EditText ip_edittext;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.setip_view);
		((TextView)findViewById(R.id.navi)).setText("设置");
		
		save_ip_btn = (Button) findViewById(R.id.save_ip_btn);
		save_ip_btn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if(StringUtil.isEmpty(ip_edittext.getText().toString())){
					ToastUtil.showToast(getApplicationContext(), "请填写接口ip地址");
					return;
				}
				SharePreferencesUtil.saveIP(SetIpActivity.this, ConfigAttrs.SET_IP, ip_edittext.getText().toString());
				SharePreferencesUtil.saveAppIsNotFirst(SetIpActivity.this, true);
				ConfigAttrs.BASE_IP = ip_edittext.getText().toString();
				Intent intent = new Intent();
				intent.setClass(SetIpActivity.this, LoginActivity.class);
				startActivity(intent);
				SetIpActivity.this.finish();
			}
		});
		ip_edittext = (EditText) findViewById(R.id.ip_edittext);
		//获取share的ip
		ip_edittext.setText(SharePreferencesUtil.getIP(SetIpActivity.this, ConfigAttrs.SET_IP));
	}
}
